import React from "react";
import ThemeContext from "../ThemeContext";
class VoteMain extends React.Component{
    static contextType = ThemeContext;
    render(){
        let {store} = this.context;
        //获取公共状态做绑定
        let {supNum,oppNum} = store.getState().vote;
        return <div className="main">
        <p>支持人数:{supNum}</p>
        <p>反对人数:{oppNum}</p>
    </div>
    }
    //组件第一次渲染完毕，让组件更新的办法，“基于store.subscribe放入到事件池中！！！
    //类组件，让组件更新，有更简单的操作：直接基于forceUpdate强制更新即可！
    componentDidMount(){
        const {store} = this.context;
        store.subscribe(()=>{
            this.forceUpdate();
        })
    }
}
export default VoteMain
